package com.chtw.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chtw.dao.LoginAccountMapper;
import com.chtw.entity.LoginAccount;
import com.chtw.entity.LoginAccountExample;

@Service
public class LoginAccountService {

	@Autowired
	private LoginAccountMapper accountMapper;
	/**
	 * 登录
	 * @param account
	 * @return
	 */
	public LoginAccount login(LoginAccount account) {
		LoginAccountExample accountExample = new LoginAccountExample();
		LoginAccountExample.Criteria cre = accountExample.createCriteria();
		cre.andAccountEqualTo(account.getAccount());
		cre.andPasswordEqualTo(account.getPassword());
		List<LoginAccount> lists = accountMapper.selectByExample(accountExample);
		if(lists.size()>0) {
			return lists.get(0);
		}
		return null;
	}
	
	/**
	 * 检查登录账户
	 * @param account
	 * @return
	 */
	public LoginAccount checkAccount(LoginAccount account) {
		LoginAccountExample accountExample = new LoginAccountExample();
		LoginAccountExample.Criteria cre = accountExample.createCriteria();
		cre.andAccountEqualTo(account.getAccount());
		List<LoginAccount> lists = accountMapper.selectByExample(accountExample);
		if(lists.size()>0) {
			return lists.get(0);
		}
		return null;
	}

	
	/**
	 * 修改密码是检查原密码
	 * @param account
	 * @return
	 */
	public LoginAccount checkPassword(LoginAccount account) {
		LoginAccountExample accountExample = new LoginAccountExample();
		LoginAccountExample.Criteria cre = accountExample.createCriteria();
		cre.andPasswordEqualTo(account.getPassword());
		cre.andAccountEqualTo(account.getAccount());
		List<LoginAccount> lists = accountMapper.selectByExample(accountExample);
		if(lists.size()>0) {
			return lists.get(0);
		}
		return null;
	}

	
	/**
	 * 修改用户密码
	 * @param account
	 * @return
	 */
	public int updatePassword(LoginAccount account) {
		LoginAccountExample accountExample = new LoginAccountExample();
		LoginAccountExample.Criteria cre = accountExample.createCriteria();
		cre.andAccountEqualTo(account.getAccount());
		int i = accountMapper.updateByExampleSelective(account, accountExample);
		return i;
	}

}
